<!DOCTYPE html>
<html lang="en">

<head>
    <title>蓝天运动</title>
    <#include "/dk/app/components/meta.html" />
    <#include "/dk/app/components/stylesheets.html" />
    <link rel="stylesheet" href="/dk/app/stylesheets/index.css?v=1">
</head>

<body>
    <div id="app">
        <div class="logo">
            <img src="https://i.loli.net/2018/12/28/5c26413b42ffe.jpg" class="am-img-responsive" style="max-height: 100px" />
        </div>
        <div class="login-form">
            <div class="login-form-field">
                <div class="login-form-field-icon">
                    <img src="/dk/app/assets/img/icon-user.png" class="am-img-responsive" />
                </div>
                <div class="login-form-field-input">
                    <input type="text" v-model="account" placeholder="姓名" />
                </div>
            </div>
            <div class="login-form-field">
                <div class="login-form-field-icon">
                    <img src="/dk/app/assets/img/icon-pwd.png" class="am-img-responsive" />
                </div>
                <div class="login-form-field-input">
                    <input type="number" v-model="mobile" placeholder="电话" />
                </div>
            </div>
            <div class="login-form-submit">
                <button class="am-btn theme-background-color1" @click="login">提交</button>
            </div>
        </div>
        <#include "/dk/app/components/footer.html" />
    </div>
    <#include "/dk/app/components/scripts.html" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9/crypto-js.min.js"></script>
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data() {
            return {
                account: '',
                mobile: '',
                password: ''
            }
        },
        mounted: function() {},
        methods: {
            login() {
                var self = this;
                if (self.account == '') {
                    msg('请填写姓名')
                    return
                }
                if (self.mobile == '') {
                    msg('请填写电话')
                    return
                }
                loading();
                // var encoded = self.aesCBC(self.password);
                var param = Qs.stringify({
                    name: self.account,
                    mobile: self.mobile,
                    // password: encoded
                });
                axios({
                    url: '/dk/app/login',
                    method: 'post',
                    data: param,
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                .then(function(response) {
                    if (response.data.status == 200) {
                        endLoading();
                        var state = "${state!''}"
                        if (state != '') {
                            window.location.href = state;   
                        }else{
                            window.location.href = "/dk/app/list";   
                        }
                        // msg("登录成功");
                    } else {
                        endLoading();
                        msg("登录失败1：" + response.data.msg);
                        console.log(response.data);
                    }
                })
                .catch(function(error) {
                    endLoading();
                    msg("登录失败2");
                    console.log(error);
                });
            },
            aesCBC(text) {
                var aesText = text;
                var key = CryptoJS.enc.Utf8.parse('${key!}');
                var iv = CryptoJS.enc.Utf8.parse('RandomInitVector');
                aesText = CryptoJS.AES.encrypt(text, key, {
                    iv: iv,
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7
                }).toString();
                return aesText;
            }
        }
    })
    </script>
    <script>
    // wx.ready(function() {
    //     initWXShare()
    // })
    </script>
</body>

</html>